"use strict";

// @ts-check
const fs = require("node:fs");
const path = require("node:path");
const { argv } = require("node:process");
const readline = require("node:readline");
const stream = require("node:stream");
const worker = require("node:worker_threads");

if (require.main === module) {
  // (async () => {
  const rs = fs.createReadStream(path.resolve(__dirname, argv[2]), {
    encoding: "utf8",
    flags: "r",
  });
  const ws = fs.createWriteStream(path.resolve(__dirname, argv[3]), {
    flags: "w+",
  });
  // rs.pipe(process.stdout);
  const rl = readline.createInterface({
    input: rs,
    crlfDelay: Infinity,
  });
  rl.on("line", (line) => {
    if (!line.trim()) {
      return;
    }
    if (line.startsWith("---")) {
      const l = /\s(\d+)\s/.exec(line.trim())?.[1];
      if (!l) {
        return;
      }
      ws.write(`${" ".repeat(Number.parseInt(l, 10)) + line}\n`);
    }
  });

  // })()
}
